x86emul/fuzz: add a state sanity checking function
authorJan Beulich <jbeulich@suse.com>
Mon, 3 Jun 2019 15:15:06 +0000 (17:15 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 3 Jun 2019 15:15:06 +0000 (17:15 +0200)
commit8a184632a17f5a6a513d5b08f3ebeae5fe1e1f27
tree0c93c9b52ca3c30e58bd9a55d0ba02c6c35b5122
parentae40f72e227b7b65f7ff8046090664881033310f
x86emul/fuzz: add a state sanity checking function

This is to accompany sanitize_input(). Just like for initial state we
want to have state between two emulated insns sane, at least as far as
assumptions in the main emulator go. Do minimal checking after segment
register, CR, and MSR writes, and roll back to the old value in case of
failure (raising #GP(0) at the same time).

In the particular case observed, a CR0 write clearing CR0.PE was
followed by a VEX-encoded insn, which the decoder accepts based on
guest address size, restricting things just outside of the 64-bit case
(real and virtual modes don't allow VEX-encoded insns). Subsequently
_get_fpu() would then assert that CR0.PE must be set (and EFLAGS.VM
clear) when trying to invoke YMM, ZMM, or OPMASK state.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
tools/fuzz/x86_instruction_emulator/fuzz-emul.c